{% extends "main/base.html" %}
{% load i18n static main_tag %}
{% block title %}{% trans '更新设备资料' %}{% endblock %}
{% block this_css %}
<link rel="stylesheet" type="text/css" href="{% static 'flatlab/assets/summernote/dist/summernote.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'flatlab/css/bootstrap-select.min.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'flatlab/assets/jquery-multi-select/css/multi-select.css' %}">
{% endblock %}
{% block content %}
<div class="panel">
    <header class="panel-heading">
        {% trans "更新设备资料" %}
        {% if form.errors %}
        <p>{% trans "提交的数据有误,请认真检查!" %}</p>
        {% endif %}
    </header>
    <div class="panel-body">
        <form method="post" enctype="multipart/form-data" class="form-horizontal">{% csrf_token %}
            {{ form.non_field_errors }}
            {% if request.user.is_authenticated %}
            <input type="hidden" name="created_by" id="id_created_by" value="{{ request.user.id }}">
            {% endif %}
            <div class="form-group col-md-12" align="right">
                <button type="submit" class="btn btn-danger" value="Update">{% trans "更新" %}</button>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.equipment_code.label_tag }}</div>
                <div class="col-sm-9">{{ form.equipment_code }}{{ form.equipment_code.errors }}</div>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.equipment_exp_code.label_tag }}</div>
                <div class="col-sm-9">{{ form.equipment_exp_code }}{{ form.equipment_exp_code.errors }}</div>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.equipment_cn.label_tag }}</div>
                <div class="col-sm-9">{{ form.equipment_cn }}{{ form.equipment_cn.errors }}</div>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.equipment_en.label_tag }}</div>
                <div class="col-sm-9">{{ form.equipment_en }}{{ form.equipment_en.errors }}</div>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.equipment_type.label_tag }}</div>
                <div class="col-sm-3">{{ form.equipment_type }}{{ form.equipment_type.errors }}</div>
                <div class="col-sm-3">{{ form.equipment_unit.label_tag }}</div>
                <div class="col-sm-3">{{ form.equipment_unit }}{{ form.equipment_unit.errors }}</div>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.power_type.label_tag }}</div>
                <div class="col-sm-9">{{ form.power_type }}{{ form.power_type.errors }}</div>
            </div>
            <div class="form-group col-md-9">
                <div class="col-sm-2">{{ form.equipment_size.label_tag }}</div>
                <div class="col-sm-10">{{ form.equipment_size }}{{ form.equipment_size.errors }}</div>
            </div>
            <!--<div class="form-group col-md-9">-->
            <!--暂时关闭设备关联功能-->
                <!--<div class="col-sm-2">related_equipment</div>-->
            <!--</div>-->
            <div class="form-group col-md-6">
                <div class="col-sm-3">{% trans '尺寸:' %}</div>
                <div class="col-sm-3">{{ form.length }}{{ form.length.errors }}</div>
                <div class="col-sm-3">{{ form.width }}{{ form.width.errors }}</div>
                <div class="col-sm-3">{{ form.height }}{{ form.height.errors }}</div>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.weight.label_tag }}</div>
                <div class="col-sm-3">{{ form.weight }}{{ form.weight.errors }}</div>
                <div class="col-sm-3">{{ form.power.label_tag }}</div>
                <div class="col-sm-3">{{ form.power }}{{ form.power.errors }}</div>
            </div>
            <div class="form-group col-md-9">
                <div class="col-sm-2">{{ form.equipment_para_cn.label_tag }}</div>
                <div class="col-sm-10">{{ form.equipment_para_cn }}{{ form.equipment_para_cn.errors }}</div>
            </div>
            <div class="form-group col-md-9">
                <div class="col-sm-2">{{ form.equipment_para_en.label_tag }}</div>
                <div class="col-sm-10">{{ form.equipment_para_en }}{{ form.equipment_para_en.errors }}</div>
            </div>
            <div class="form-group col-md-9">
                <div class="col-sm-2">{{ form.related_materials.label_tag }}</div>
                <div class="col-sm-10">{{ form.related_materials }}{{ form.related_materials.errors }}</div>
            </div>
            <div class="form-group col-md-9">
                <div class="col-sm-2">{{ form.notes.label_tag }}</div>
                <div class="col-sm-10">{{ form.notes }}{{ form.notes.errors }}</div>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.drawing_en.label_tag }}</div>
                <div class="col-sm-6">{{ form.drawing_en }}{{ form.drawing_en.errors }}</div>
                <div class="col-sm-3">{% if object.drawing_en  %}<a href="{{ object.drawing_en|qiniu }}" target="_blank"><span class="btn btn-info btn-xs">{% trans '当前英文图纸' %}</span></a>{% endif %}</div>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.file_en.label_tag }}</div>
                <div class="col-sm-6">{{ form.file_en }}{{ form.file_en.errors }}</div>
                <div class="col-sm-3">{% if object.file_en  %}<a href="{{ object.file_en|qiniu }}" target="_blank"><span class="btn btn-info btn-xs">{% trans '当前英文资料' %}</span></a>{% endif %}</div>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.drawing_cn.label_tag }}</div>
                <div class="col-sm-6">{{ form.drawing_cn }}{{ form.drawing_cn.errors }}</div>
                <div class="col-sm-3">{% if object.drawing_cn  %}<a href="{{ object.drawing_cn|qiniu }}" target="_blank"><span class="btn btn-info btn-xs">{% trans '当前中文图纸' %}</span></a>{% endif %}</div>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.file_cn.label_tag }}</div>
                <div class="col-sm-6">{{ form.file_cn }}{{ form.file_cn.errors }}</div>
                <div class="col-sm-3">{% if object.file_cn  %}<a href="{{ object.file_cn|qiniu }}" target="_blank"><span class="btn btn-info btn-xs">{% trans '当前中文资料' %}</span></a>{% endif %}</div>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.file_3d.label_tag }}</div>
                <div class="col-sm-6">{{ form.file_3d }}{{ form.file_3d.errors }}</div>
                <div class="col-sm-3">{% if object.file_3d  %}<a href="{{ object.file_3d|qiniu }}" target="_blank"><span class="btn btn-info btn-xs">{% trans '当前3D图形' %}</span></a>{% endif %}</div>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.equipment_img.label_tag }}</div>
                <div class="col-sm-6">{{ form.equipment_img }}{{ form.equipment_img.errors }}</div>
                <div class="col-sm-3">{% if object.equipment_img  %}<a href="{{ object.equipment_img|qiniu }}" target="_blank"><span class="btn btn-info btn-xs">{% trans '当前设备图片' %}</span></a>{% endif %}</div>
            </div>
            <div class="form-group col-md-6">
                <div class="col-sm-3">{{ form.file_3s.label_tag }}</div>
                <div class="col-sm-6">{{ form.file_3s }}{{ form.file_3s.errors }}</div>
                <div class="col-sm-3">{% if object.file_3s  %}<a href="{{ object.file_3s|qiniu }}" target="_blank"><span class="btn btn-info btn-xs">{% trans '当前设备3视图' %}</span></a>{% endif %}</div>
            </div>
            <div class="form-group col-md-12" align="right">
                <button type="submit" class="btn btn-danger" value="Update">{% trans "更新" %}</button>
            </div>
        </form>
    </div>
</div>
{% endblock %}
{% block this_js %}
<script type="text/javascript" src="{% static 'flatlab/js/bootstrap-switch.js' %}"></script>
<script type="text/javascript" src="{% static 'flatlab/js/bootstrap-select.min.js' %}"></script>
<script type="text/javascript" src="{% static 'flatlab/assets/jquery-multi-select/js/jquery.multi-select.js' %}"></script>
<script type="text/javascript" src="{% static 'flatlab/assets/jquery-multi-select/js/jquery.quicksearch.js' %}"></script>
<script type="text/javascript" src="{% static 'flatlab/assets/summernote/dist/summernote.min.js' %}"></script>
<script>
jQuery(document).ready(function(){
    $('.summernote').summernote({
        height: 200,                 // set editor height
        minHeight: null,             // set minimum height of editor
        maxHeight: null,             // set maximum height of editor
        focus: true                 // set focus to editable area after initializing summernote
    });
});
</script>
<script>
    $('#id_equipment_size').multiSelect({
        selectableHeader: "<div>可选的规格</div><input type='text' class='form-control search-input' autocomplete='off' placeholder='search...'>",
        selectionHeader: "<div>选中的规格</div><input type='text' class='form-control search-input' autocomplete='off' placeholder='search...'>",
        afterInit: function (ms) {
            var that = this,
                $selectableSearch = that.$selectableUl.prev(),
                $selectionSearch = that.$selectionUl.prev(),
                selectableSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selectable:not(.ms-selected)',
                selectionSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selection.ms-selected';

            that.qs1 = $selectableSearch.quicksearch(selectableSearchString)
                .on('keydown', function (e) {
                    if (e.which === 40) {
                        that.$selectableUl.focus();
                        return false;
                    }
                });

            that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
                .on('keydown', function (e) {
                    if (e.which == 40) {
                        that.$selectionUl.focus();
                        return false;
                    }
                });
        },
        afterSelect: function () {
            this.qs1.cache();
            this.qs2.cache();
        },
        afterDeselect: function () {
            this.qs1.cache();
            this.qs2.cache();
        }
    });
</script>
<script>
    $('#id_related_equipment').multiSelect({
        selectableHeader: "<input type='text' class='form-control search-input' autocomplete='off' placeholder='search...'>",
        selectionHeader: "<input type='text' class='form-control search-input' autocomplete='off' placeholder='search...'>",
        afterInit: function (ms) {
            var that = this,
                $selectableSearch = that.$selectableUl.prev(),
                $selectionSearch = that.$selectionUl.prev(),
                selectableSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selectable:not(.ms-selected)',
                selectionSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selection.ms-selected';

            that.qs1 = $selectableSearch.quicksearch(selectableSearchString)
                .on('keydown', function (e) {
                    if (e.which === 40) {
                        that.$selectableUl.focus();
                        return false;
                    }
                });

            that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
                .on('keydown', function (e) {
                    if (e.which == 40) {
                        that.$selectionUl.focus();
                        return false;
                    }
                });
        },
        afterSelect: function () {
            this.qs1.cache();
            this.qs2.cache();
        },
        afterDeselect: function () {
            this.qs1.cache();
            this.qs2.cache();
        }
    });
</script>
{% endblock %}